* Master dofile - this shows the order in which all do-files should be run to recreate Stoye (2025)
** Note: This relies on data from the Hospital Episode Statistics and NHS Electronic Staff Record, which I do not have permission to share. Please see readme for further information on applying for these data.

* Set filepaths here (and in individual do-files if running them separately) - these globals are set here for all do-files listed
global rawdata ""
global rawdata_op ""
global eddata ""
global mortalitydata ""
global consids ""
global savedata ""
global dofile ""
global inputs  ""
global results ""
global staffdata ""

* Build data
do "$dofile/1. extract_records.do" /* Extracts patient records for AMI patients */
do "$dofile/2. make_cardiologist_list.do" /* Extracts patient records for AMI patients */
do "$dofile/3. build_patient_data.do" /* Cleans patient dataset and identifies episode of care that we want to focus on */
do "$dofile/4. make_analysis_dataset_part1.do" /* Merges in various datasets and starts to create analysis dataset. Also calls do-files (4a) that create records of previous treatment */
do "$dofile/5. make_analysis_dataset_part2.do" /* Finalises creating the dataset used in the baseline analysis. Also calls do-files (5a and 5b) that create connected sets and create measures of cardiologist experience */

* Descriptives
do "$dofile/6. make_sumstats.do" /* Produces results in Tables 1 and 2, Appendix Table A1 and Appendix Figures A1 and A2 */

* Results (Section 5.1)
do "$dofile/7a. make_table3.do" /* Produces results in Table 3 (baseline results) */
do "$dofile/7b. make_figure1_figureA3.do" /* Produces Figure 1 and Figure A3 */
do "$dofile/7c. make_TableA2.do" /* Produces Table A2 */

* Robustness checks (Section 5.2 and 5.3)
do "$dofile/8a. make_figure2.do" /* Produces Figure 2 */
do "$dofile/8b. make_pastop.do" /* Creates record of past outpatient care for AMI patients, used in results in Table 4 */
do "$dofile/8c. make_pastae.do" /* Creates record of past A&E (ED) care for AMI patients, used in results in Table 4 */
do "$dofile/8d. make_gpadmits.do" /* Creates record of elective and emergency hospital admissions at the GP practice level, used in results in Table 4 */
do "$dofile/8e. make_table4.do" /* Produces results displayed in Table 4 */
do "$dofile/8f. make_tableA3.do" /* Produces results displayed in Table A3 - calls two other dofiles (8fi and 8fii) to create the analysis dataset using the sample from 2009 onwards */
do "$dofile/8g. make_figureA4.do" /* Produces Figure A4 */
do "$dofile/8h. make_tableA4_cols1and2.do" /* Produces columns 1 and 2 in Table A4 - calls dofile 8hi to create the sample of hospitals that always conducted PCI throughout the period */
do "$dofile/8i. make_tableA4_cols3and4.do" /* Produces columns 3 and 4 in Table A4 - calls dofiles 8ii and 8iii to create the sample of patients without a previous interaction with the treating doctor */
do "$dofile/8j. make_figure_A5_and_A6.do" /* Produces Figures A5 and A6 */
do "$dofile/8k. test_trust_specific_seasonality.do" /* Seasonality test in footnote 31 */
do "$dofile/8l. rsquared_analysis.do" /* R-squared comparisons between models in Section 5.2.2 */
do "$dofile/8m. make_Table5.do" /* Produces results in Table 5 */
do "$dofile/8o. make_Table6.do" /* Produces results in Table 6 (columns 2 and 3, column 1 is the same as column 4 in Table 3) */
do "$dofile/8p. make_TableA5.do" /* Produces results for Table A5 */
do "$dofile/8q. KSS_footnote37.do" /* Sets up data and produces comparison results for KSS tests in footnote 37 */

* Hospital correlates (Section 5.4)
do "$dofile/9a. make_Figure3_and_TableA6.do" /* Makes Figure 3 and results for Table A6 */
do "$dofile/9b. make_FigureA7.do" /* Makes Figure A7 */
do "$dofile/9c. make_Table7.do" /* Makes results Table 7 */
do "$dofile/9d. make_figureA8.do" /* Makes Figure A8 */

* Reallocation exercises (Section 6)
do "$dofile/10a. make_Figure4_and_FigureA9.do" /* Makes Figure 4 and Figure A9 */
do "$dofile/10b. reallocation_calculations_section6.do" /* Calculates mortality gains from various reallocation exercises discussed in Section 6.2 */


